package pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class ThreadPoolDemo2 {
    static int count = 0;
    public static void main(String[] args) {
        ExecutorService threadPool = Executors.newFixedThreadPool(10);
        for (int i = 0; i < 100; i++) {
            threadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println(Thread.currentThread().getName());

                }
            });
        }
        //获取线程池中的信息
        ThreadPoolExecutor executor = (ThreadPoolExecutor) threadPool;//强转
        System.out.println("线程池中的线程数：" + executor.getPoolSize());
        System.out.println("当前排队线程数：" + executor.getQueue().size());
        System.out.println("已执行完成的线程数：" + executor.getCompletedTaskCount());
        threadPool.shutdown();
    }
}
